package com.jifeng.sterilizer.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jifeng.sterilizer.entity.UserDeviceEntity;
import com.jifeng.sterilizer.service.UserDeviceService;
import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.R;



/**
 * 用户消毒器表
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-07-26 15:15:14
 */
@RestController
@RequestMapping("sterilizer/userdevice")
public class UserDeviceController {
    @Autowired
    private UserDeviceService userDeviceService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userDeviceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserDeviceEntity userDevice = userDeviceService.getById(id);

        return R.ok().put("userDevice", userDevice);
    }

    /**
     * 绑定用户和消毒机
     */
    @PostMapping("/addUserDevice")
    public R save(@RequestBody UserDeviceEntity userDevice){
		R rs= userDeviceService.addUserDevice(userDevice);

        return rs;
    }

    /**
     * 解除用户和消毒机绑定
     */
    @PutMapping("/removeUserDevice")
    public R removeUserDevice(@RequestBody UserDeviceEntity userDevice){
        R rs= userDeviceService.removeUserDevice(userDevice);

        return rs;
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody UserDeviceEntity userDevice){
		userDeviceService.updateById(userDevice);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userDeviceService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
